package py.com.alfa.escriba.gui.controller.formatter;


import java.text.ParseException;
import java.util.Locale;

import org.springframework.format.Formatter;

import py.com.alfa.escriba.gui.dto.admin.ControlesVehiculosDTO;



public class ControlesVehiculosFormatter implements Formatter<ControlesVehiculosDTO>{

//	private final Logger logger = LoggerFactory.getLogger(ControlesVehiculosFormatter.class);
	
	@Override
	public String print(ControlesVehiculosDTO object, Locale locale) {
		StringBuffer sb = new StringBuffer();
		sb.append(object.getId());
		if(object.getIdvehiculo() != null){
			sb.append("|").append(object.getIdvehiculo());
		}
		return sb.toString();
	}

	@Override
	public ControlesVehiculosDTO parse(String text, Locale locale) throws ParseException {
		ControlesVehiculosDTO obj = new ControlesVehiculosDTO();
		if(text.contains("|")){
			String[] split = text.split("\\|");
			obj.setId(Long.parseLong(split[0]));
			obj.setIdvehiculo(Long.parseLong(split[1]));			
		}else{
			obj.setId(Long.parseLong(text));
		}
		return obj;
	}
	
}
